import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'DataList.dart';
import 'myCard.dart';
// 有状态组件和列表渲染(优化封装)
void main() => runApp(MaterialApp(
  home: Home(),
));

// 有状态组件
class Home extends StatefulWidget {
  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  List<DataList> mylists= [
    DataList( key: "姓名", value: "张三12" ),
    DataList( key: "公司", value: "阿里巴巴" ),
    DataList( key: "职位", value: "前端工程师" ),
    DataList( key: "电话", value: "12345678901" ),
  ];

  Widget GetItem(List<DataList> lits) {
    return Column(
      // children: lits.map((item) {
      //   return CardItem(item);
      // }).toList(),
      children: lits.map((item) => myCard(item, () => {
        // 事件传递
        // print("点击了卡片222");
        setState(() {
          mylists.remove(item);
        })
      })).toList(),
    );
  }

  // 重写Widget build
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[900],
      appBar: AppBar(
        title: Text(
            "Demo在线",
            style: TextStyle(
              color: Colors.white,
            )
        ),
        backgroundColor: Colors.grey[800],
        centerTitle: true,
      ),
      body: Padding(
        padding: const EdgeInsets.all(30.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Center(
              child: CircleAvatar(
                radius: 50.0,
                backgroundImage: AssetImage('assets/images/2.png'),
              ),
            ),
            Divider(
              height: 50.0,
              color: Colors.grey[600],
            ),
            // 自己定义组件Widget
            GetItem(
              mylists
            ),
            Row(
              children: [
                Icon(
                  Icons.email,
                  color: Colors.grey[600],
                ),
                SizedBox(width: 10),
                Text(
                  "2293188960@qq.com",
                  style: TextStyle(
                    color: Colors.grey[600],
                    fontSize: 20.0,
                  ),
                ),
              ],
            )
          ],
        )
      ),
    );
  }
}
